﻿/***********************************************************************
 * <copyright file="Model.cs" company="BUCA JSC">
 * -->    Copyright (C) statement. All right reserved
 * </copyright>
 * 
 * Created:   Tuanhm
 * Email:    Tuanhm@humg@gmail.com
 * Website:
 * Create Date: Thursday, March 27, 2014
 * Usage:  
 * 
 * RevisionHistory: 
 * Date         Author               Description 
 * 
 * ************************************************************************/

using System;
using System.Linq;
using System.Collections.Generic;
using WindowsForms.AOnline.Model.AccountingServiceReference;
using WindowsForms.AOnline.Model.BusinessObjects.Report;
using WindowsForms.AOnline.Model.BusinessObjects.Report.Stock;
using WindowsForms.AOnline.Model.DataTransferObjectMapper;
using WindowsForms.AOnline.Model.DataTransferObjectMapper.Voucher;
using WindowsForms.AOnline.Model.BusinessObjects.Dictionary;


namespace WindowsForms.AOnline.Model
{
    /// <summary>
    /// 
    /// </summary>
    public class Model : RepositoryBase, IModel 
    {
        #region Statics
       // private static readonly SalaryFacade SalaryFacadeClient = new SalaryFacade();


        ///// <summary>
        ///// Adds RequestId, ClientTag, and AccessToken to all request types.
        ///// </summary>
        ///// <typeparam name="T">The request type.</typeparam>
        ///// <param name="request">The request</param>
        ///// <returns>Fully prepared request, ready to use.</returns>
        //private static T PrepareRequest<T>(T request) where T : RequestBase
        //{
        //    return request;
        //}
        #endregion

        #region EmployTest

        public int GetPageSizeEmployTests()
        {
            var request = new EmployTestRequest().Prepare();
            request.LoadOptions = new[] { "TotalPage" };

            var response = Client.GetEmployTests(request);
            Correlate(request, response);
            return response.TotalPage;
        }

        public IList<BusinessObjects.Dictionary.EmployTestModel> GetEmployTests(int currentPage)
        {
            var request = new EmployTestRequest().Prepare();

            request.LoadOptions = new[] { "EmployTests" };
            request.Options = OptionType.IsUnit | OptionType.IsPaging;
            request.CurrentPage = currentPage;

            var response = Client.GetEmployTests(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.EmployTests);
        }
        public EmployTestModel GetEmploy(int EmployId) 
        {
            var request = new EmployTestRequest().Prepare();
            request.LoadOptions = new[] { "EmployTest" };
            request.Criteria = new EmployTestCriteria() { EmployTestId = EmployId };
            var response = Client.GetEmployTests(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObject(response.EmployTest);
        }

        public string AddEmploy(BusinessObjects.Dictionary.EmployTestModel Employ)
        {
            var request = new EmployTestRequest().Prepare();
            request.Action = "Create";
            request.EmployTest = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(Employ); 
            var response = Client.SetEmployTests(request);
            Correlate(request, response);
            return response.Message;
        }

        public string UpdateEmploy(BusinessObjects.Dictionary.EmployTestModel Employ)
        {
            var request = new EmployTestRequest().Prepare();
            request.Action = "Update";
            request.EmployTest = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(Employ); 
            var response = Client.SetEmployTests(request);
            Correlate(request, response);
            return response.Message;
        }

        public string DeleteEmploy(int EmployId)
        {
            var request = new EmployTestRequest().Prepare();
            request.Action = "Delete";
            request.Criteria = new EmployTestCriteria() { EmployTestId = EmployId };

            var response = Client.SetEmployTests(request);
            Correlate(request, response);
            return response.Message;
        }

        #endregion

        #region DbOption

        /// <summary>
        /// Gets the database options.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.ApplicationException"></exception>
        public IList<DbOptionModel> GetDbOptions()
        {
            var request = new DbOptionRequest().Prepare();
            request.LoadOptions = new[] { "DbOptions" };
            request.Options = OptionType.IsUnit;

            var response = Client.GetDbOptions(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.DbOptions);
        }

        /// <summary>
        /// Updates the database option.
        /// </summary>
        /// <param name="dbOptions">The database options.</param>
        /// <returns></returns>
        public string UpdateDbOption(List<DbOptionModel> dbOptions)
        {
            var request = new DbOptionRequest().Prepare();
            request.Action = "Update";
            request.DbOptions = (DbOptionDto[]) WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObjects(dbOptions);
            var response = Client.SetDbOptions(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        #endregion

        #region Account 

        
        public IList<AccountModel> GetAllAccounts()
        {
            var request = new AccountRequest().Prepare();
            request.LoadOptions = new[] { "Accounts" };
            request.Options = OptionType.IsUnit | OptionType.NonPaging;

            var response = Client.GetAccounts(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Accounts).ToList();
        }

        public IList<AccountModel> GetAccountsAccountingObject()
        {
            var request = new AccountRequest().Prepare();
            request.LoadOptions = new[] { "AccountingObject" };

            var response = Client.GetAccounts(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Accounts);
        }

        public IList<AccountModel> GetAccountsTax()
        {
            var request = new AccountRequest().Prepare();
            request.LoadOptions = new[] { "Tax" };

            var response = Client.GetAccounts(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Accounts);
        }

        public IList<AccountModel> GetAccountsFixedasset()
        {
            var request = new AccountRequest().Prepare();
            request.LoadOptions = new[] { "Fixedasset" };

            var response = Client.GetAccounts(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Accounts);
        }


        public IList<AccountModel> GetAccountsInventoryItem()
        {
            var request = new AccountRequest().Prepare();
            request.LoadOptions = new[] { "InventoryItem" };

            var response = Client.GetAccounts(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Accounts);
        }

        public int GetPageSizeAccounts() 
        {
            var request = new AccountRequest().Prepare();
            request.LoadOptions = new[] { "TotalPage" };

            var response = Client.GetAccounts(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.TotalPage;
        }

        public IList<AccountModel> GetAccounts(int currentPage)
        {
            var request = new AccountRequest().Prepare();

            request.LoadOptions = new[] { "Accounts" };
            request.Options = OptionType.IsUnit | OptionType.IsPaging;
            request.CurrentPage = currentPage;

            var response = Client.GetAccounts(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Accounts);
  
        }

        public IList<AccountModel> GetAccountsForComboTree(int accountId)
        {
            var request = new AccountRequest().Prepare();
            request.LoadOptions = new[] { "Accounts", "ForComboTree" };
            request.Options = OptionType.IsUnit;
            request.Criteria = new AccountCriteria() { AccountId = accountId };

            var response = Client.GetAccounts(request);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);

            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Accounts);
        }

        public IList<AccountModel> GetAccountsActive()
        {
            throw new NotImplementedException();
        }


        public AccountModel GetAccount(int accountId)
        {
            var request = new AccountRequest().Prepare();
            request.LoadOptions = new[] { "Account" };
            request.Criteria = new AccountCriteria() { AccountId = accountId };
            var response = Client.GetAccounts(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObject(response.Account);
        }

        public string AddAccount(AccountModel account)
        {
            var request = new AccountRequest().Prepare();
            request.Action = "Create";
            request.Account = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(account);
            var response = Client.SetAccounts(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string UpdateAccount(AccountModel account)
        {
            var request = new AccountRequest().Prepare();
            request.Action = "Update";
            request.Account = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(account);
            var response = Client.SetAccounts(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string DeleteAccount(int accountId)
        {
            var request = new AccountRequest().Prepare();
            request.Action = "Delete";
            request.Criteria = new AccountCriteria() { AccountId = accountId };

            var response = Client.SetAccounts(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }
        #endregion

        #region ItemTransaction

        public BusinessObjects.Inventory.ItemTransactionModel GetItemTransactionVoucher(string refNo)
        {
            throw new NotImplementedException();
        }

        public IList<BusinessObjects.Inventory.ItemTransactionModel> GetItemTransactionVoucherByRefTypeId(int refTypeId, int page)
        {

            var request = new ItemTransactionRequest().Prepare();

            request.LoadOptions = new[] { "ItemTransactions" };
            request.Options = OptionType.IsUnit | OptionType.IsPaging;
            request.CurrentPage = page;
            request.RefType = refTypeId;

            var response = Client.GetItemTransactions(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return DataTransferObjectMapper.Voucher.Mapper.FromDataTransferObjects(response.ItemTransactions);
  
        }

        public BusinessObjects.Inventory.ItemTransactionModel GetItemTransactionVoucher(long itemTransactionId)
        {
            var request = new ItemTransactionRequest().Prepare();
            request.LoadOptions = new[] { "ItemTransaction" };
            request.Criteria = new ItemTransactionCriteria { ItemTransactionId = itemTransactionId };
            request.Options = OptionType.IsDetail;
            var response = Client.GetItemTransactions(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return DataTransferObjectMapper.Voucher.Mapper.FromDataTransferObject(response.ItemTransaction, response.ItemTransactionDetails);
        }

        public string AddItemTransactionVoucher(BusinessObjects.Inventory.ItemTransactionModel itemTransaction)
        {
            var request = new ItemTransactionRequest().Prepare();
            request.Action = "Create";
            request.ItemTransaction = DataTransferObjectMapper.Voucher.Mapper.ToDataTransferObject(itemTransaction);
            //Thêm - wcf
            request.ItemTransactionDetails = DataTransferObjectMapper.Voucher.Mapper.ToDataTransferObject(itemTransaction.ItemTransactionDetails);
            var response = Client.SetItemTransactions(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string UpdateItemTransactionVoucher(BusinessObjects.Inventory.ItemTransactionModel itemTransaction)
        {
            var request = new ItemTransactionRequest().Prepare();
            request.Action = "Update";
            request.ItemTransaction = DataTransferObjectMapper.Voucher.Mapper.ToDataTransferObject(itemTransaction);
            //Thêm - wcf
            request.ItemTransactionDetails = DataTransferObjectMapper.Voucher.Mapper.ToDataTransferObject(itemTransaction.ItemTransactionDetails);
            var response = Client.SetItemTransactions(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string DeleteItemTransactionVoucher(long itemTransactionId)
        {
            var request = new ItemTransactionRequest().Prepare();
            request.Action = "Delete";
            request.Criteria = new ItemTransactionCriteria { ItemTransactionId = itemTransactionId };

            var response = Client.SetItemTransactions(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }


        public int GetPageSizeItemTransactions(int refTypeId)
        {
            var request = new ItemTransactionRequest().Prepare();
            request.LoadOptions = new[] { "TotalPage" };
            request.RefType = refTypeId;
            var response = Client.GetItemTransactions(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.TotalPage;
        }

        #endregion

        #region AutoBusiness

        public IList<AutoBusinessModel> GetAllAutoBusinesss()
        {
            var request = new AutoBusinessRequest().Prepare();
            request.LoadOptions = new[] { "AutoBusinesss" };
            request.Options = OptionType.IsUnit | OptionType.NonPaging;

            var response = Client.GetAutoBusinesss(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.AutoBusinesss).ToList();
        }

        public int GetPageSizeAutoBusinesss()
        {
            var request = new AutoBusinessRequest().Prepare();
            request.LoadOptions = new[] { "TotalPage" };

            var response = Client.GetAutoBusinesss(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.TotalPage;
        }

        public IList<AutoBusinessModel> GetAutoBusinesss(int currentPage)
        {
            var request = new AutoBusinessRequest().Prepare();

            request.LoadOptions = new[] { "AutoBusinesss" };
            request.Options = OptionType.IsUnit | OptionType.IsPaging;
            request.CurrentPage = currentPage;

            var response = Client.GetAutoBusinesss(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.AutoBusinesss);
        }

        public AutoBusinessModel GetAutoBusiness(int autoBusinessId)
        {
            var request = new AutoBusinessRequest().Prepare();
            request.LoadOptions = new[] { "AutoBusiness" };
            request.Criteria = new AutoBusinessCriteria() { AutoBusinessId = autoBusinessId };
            var response = Client.GetAutoBusinesss(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObject(response.AutoBusiness);
        }

        public string AddAutoBusiness(AutoBusinessModel autoBusiness)
        {
            var request = new AutoBusinessRequest().Prepare();
            request.Action = "Create";
            request.AutoBusiness = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(autoBusiness);
            var response = Client.SetAutoBusinesss(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string UpdateAutoBusiness(AutoBusinessModel autoBusiness)
        {
            var request = new AutoBusinessRequest().Prepare();
            request.Action = "Update";
            request.AutoBusiness = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(autoBusiness);
            var response = Client.SetAutoBusinesss(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string DeleteAutoBusiness(int autoBusinessId)
        {
            var request = new AutoBusinessRequest().Prepare(); 
            request.Action = "Delete";
            request.Criteria = new AutoBusinessCriteria() { AutoBusinessId = autoBusinessId };

            var response = Client.SetAutoBusinesss(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }
        #endregion

        #region AutoNumber
        public int GetPageSizeAutoNumbers()
        {
            throw new NotImplementedException();
        }

        public IList<AutoNumberModel> GetAutoNumbers(int currentPage)
        {
            throw new NotImplementedException();
        }

        public AutoNumberModel GetAutoNumber(int autoNumberId)
        {
            throw new NotImplementedException();
        }

        public string AddAutoNumber(AutoNumberModel autoNumber)
        {
            throw new NotImplementedException();
        }

        public string UpdateAutoNumber(AutoNumberModel autoNumber)
        {
            throw new NotImplementedException();
        }

        public string DeleteAutoNumber(int autoNumberId)
        {
            throw new NotImplementedException();
        }
        public AutoNumberModel GetAutoNumberByRefType(int refType)
        {
            var request = new AutoNumberRequest().Prepare();
            request.LoadOptions = new[] { "AutoNumber", "RefType" };
            request.RefTypeId = refType;

            var response = Client.GetAutoNumbers(request);
            if (response.Acknowledge != AcknowledgeType.Success)
                throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObject(response.AutoNumber);
            // Mapper.FromDataTransferObject(response.AutoNumber);
        }
          #endregion

        #region Customer

        public List<CustomerModel> GetAllCustomers()
        {
            var request = new CustomerRequest().Prepare();
            request.LoadOptions = new[] { "Customers" };
            request.Options = OptionType.IsUnit | OptionType.NonPaging;

            var response = Client.GetCustomers(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Customers).ToList();
        }

        public int GetPageSizeCustomers()
        {
            var request = new CustomerRequest().Prepare();
            request.LoadOptions = new[] { "TotalPage" };

            var response = Client.GetCustomers(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.TotalPage;
        }
        public List<CustomerModel> GetCustomersByActive(bool isActive)
        {
            var request = new CustomerRequest().Prepare();

            request.LoadOptions = new[] { "Customers" };
         //   request.Options = OptionType.IsUnit | OptionType.IsPaging;
         //   request.CurrentPage = currentPage;

            var response = Client.GetCustomers(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Customers).ToList();
        }

        public IList<CustomerModel> GetCustomers(int currentPage)
        {
            var request = new CustomerRequest().Prepare();

            request.LoadOptions = new[] { "Customers" };
            request.Options = OptionType.IsUnit | OptionType.IsPaging;
            request.CurrentPage = currentPage;

            var response = Client.GetCustomers(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Customers);
        }

        public CustomerModel GetCustomer(int customerId)
        {
            var request = new CustomerRequest().Prepare();
            request.LoadOptions = new[] { "Customer" };
            request.Criteria = new CustomerCriteria() { CustomerId = customerId };
            var response = Client.GetCustomers(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObject(response.Customer);
        }

        public string AddCustomer(CustomerModel customer)
        {
            var request = new CustomerRequest().Prepare();
            request.Action = "Create";
            request.Customer = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(customer);
            var response = Client.SetCustomers(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string UpdateCustomer(CustomerModel customer)
        {
            var request = new CustomerRequest().Prepare();
            request.Action = "Update";
            request.Customer = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(customer);
            var response = Client.SetCustomers(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string DeleteCustomer(int customerId)
        {
            var request = new CustomerRequest().Prepare();
            request.Action = "Delete";
            request.Criteria = new CustomerCriteria() { CustomerId = customerId };

            var response = Client.SetCustomers(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }
        #endregion

        #region Department
        public int GetPageSizeDepartments()
        {
            var request = new DepartmentRequest().Prepare();
            request.LoadOptions = new[] { "TotalPage" };

            var response = Client.GetDepartments(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.TotalPage;
        }

        public IList<DepartmentModel> GetDepartments(int currentPage)
        {
            var request = new DepartmentRequest().Prepare();

            request.LoadOptions = new[] { "Departments" };
            request.Options = OptionType.IsUnit | OptionType.IsPaging;
            request.CurrentPage = currentPage;

            var response = Client.GetDepartments(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Departments);
        }

        public DepartmentModel GetDepartment(int departmentId)
        {
            var request = new DepartmentRequest().Prepare();
            request.LoadOptions = new[] { "Department" };
            request.Criteria = new DepartmentCriteria() { DepartmentId = departmentId };
            var response = Client.GetDepartments(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObject(response.Department);
        }

        public string AddDepartment(DepartmentModel department)
        {
            var request = new DepartmentRequest().Prepare();
            request.Action = "Create";
            request.Department = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(department);
            var response = Client.SetDepartments(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string UpdateDepartment(DepartmentModel department)
        {
            var request = new DepartmentRequest().Prepare();
            request.Action = "Update";
            request.Department = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(department);
            var response = Client.SetDepartments(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string DeleteDepartment(int departmentId)
        {
            var request = new DepartmentRequest().Prepare();
            request.Action = "Delete";
            request.Criteria = new DepartmentCriteria() { DepartmentId = departmentId };

            var response = Client.SetDepartments(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }


        public IList<DepartmentModel> GetAllDepartments()
        {
            var request = new DepartmentRequest().Prepare();
            request.LoadOptions = new[] { "Departments" };
            request.Options = OptionType.IsUnit | OptionType.NonPaging;

            var response = Client.GetDepartments(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Departments).ToList();
        }
        #endregion

        #region InventoryItem

        public IList<InventoryItemModel> GetAllInventoryItems()
        {
            var request = new InventoryItemRequest().Prepare();
            request.LoadOptions = new[] { "InventoryItems" };
            request.Options = OptionType.IsUnit | OptionType.NonPaging;

            var response = Client.GetInventoryItems(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.InventoryItems).ToList();
        }
        public int GetPageSizeInventoryItems()
        {
            var request = new InventoryItemRequest().Prepare();
            request.LoadOptions = new[] { "TotalPage" };

            var response = Client.GetInventoryItems(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.TotalPage;
        }

        public IList<InventoryItemModel> GetInventoryItems(int currentPage)
        {
            var request = new InventoryItemRequest().Prepare();

            request.LoadOptions = new[] { "InventoryItems" };
            request.Options = OptionType.IsUnit | OptionType.IsPaging;
            request.CurrentPage = currentPage;

            var response = Client.GetInventoryItems(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.InventoryItems);
        }

        public InventoryItemModel GetInventoryItem(int inventoryItemId)
        {
            var request = new InventoryItemRequest().Prepare();
            request.LoadOptions = new[] { "InventoryItem" };
            request.Criteria = new InventoryItemCriteria() { InventoryItemId = inventoryItemId };
            var response = Client.GetInventoryItems(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObject(response.InventoryItem);
        }

        public string AddInventoryItem(InventoryItemModel inventoryItem)
        {
            var request = new InventoryItemRequest().Prepare();
            request.Action = "Create";
            request.InventoryItem = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(inventoryItem);
            var response = Client.SetInventoryItems(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string UpdateInventoryItem(InventoryItemModel inventoryItem)
        {
            var request = new InventoryItemRequest().Prepare();
            request.Action = "Update";
            request.InventoryItem = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(inventoryItem);
            var response = Client.SetInventoryItems(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string DeleteInventoryItem(int inventoryItemId)
        {
            var request = new InventoryItemRequest().Prepare();
            request.Action = "Delete";
            request.Criteria = new InventoryItemCriteria() { InventoryItemId = inventoryItemId };

            var response = Client.SetInventoryItems(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }
        #endregion

        #region Stock


        public IList<StockModel> GetAllStocks()
        {
            var request = new StockRequest().Prepare();
            request.LoadOptions = new[] { "Stocks" };
            request.Options = OptionType.IsUnit | OptionType.NonPaging;

            var response = Client.GetStocks(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Stocks).ToList();
        }


        public int GetPageSizeStocks()
        {
            var request = new StockRequest().Prepare();
            request.LoadOptions = new[] { "TotalPage" };

            var response = Client.GetStocks(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.TotalPage;
        }

        public IList<StockModel> GetStocks(int currentPage)
        {
            var request = new StockRequest().Prepare();

            request.LoadOptions = new[] { "Stocks" };
            request.Options = OptionType.IsUnit | OptionType.IsPaging;
            request.CurrentPage = currentPage;

            var response = Client.GetStocks(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Stocks);
        }

        public StockModel GetStock(int stockId)
        {
            var request = new StockRequest().Prepare();
            request.LoadOptions = new[] { "Stock" };
            request.Criteria = new StockCriteria() { StockId = stockId };
            var response = Client.GetStocks(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObject(response.Stock);
        }

        public string AddStock(StockModel stock)
        {
            var request = new StockRequest().Prepare();
            request.Action = "Create";
            request.Stock = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(stock);
            var response = Client.SetStocks(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string UpdateStock(StockModel stock)
        {
            var request = new StockRequest().Prepare();
            request.Action = "Update";
            request.Stock = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(stock);
            var response = Client.SetStocks(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string DeleteStock(int stockId)
        {
            var request = new StockRequest().Prepare();
            request.Action = "Delete";
            request.Criteria = new StockCriteria() { StockId = stockId };

            var response = Client.SetStocks(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }
        #endregion

        #region FixedAsset
        public int GetPageSizeFixedAssets()
        {
            var request = new FixedAssetRequest().Prepare();
            request.LoadOptions = new[] { "TotalPage" };

            var response = Client.GetFixedAssets(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.TotalPage;
        }

        public IList<FixedAssetModel> GetFixedAssets(int currentPage)
        {
            var request = new FixedAssetRequest().Prepare();

            request.LoadOptions = new[] { "FixedAssets" };
            request.Options = OptionType.IsUnit | OptionType.IsPaging;
            request.CurrentPage = currentPage;

            var response = Client.GetFixedAssets(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.FixedAssets);
        }

        public FixedAssetModel GetFixedAsset(int stockId)
        {
            var request = new FixedAssetRequest().Prepare();
            request.LoadOptions = new[] { "FixedAsset" };
            request.Criteria = new FixedAssetCriteria() { FixedAssetId = stockId };
            var response = Client.GetFixedAssets(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObject(response.FixedAsset);
        }

        public string AddFixedAsset(FixedAssetModel stock)
        {
            var request = new FixedAssetRequest().Prepare();
            request.Action = "Create";
            request.FixedAsset = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(stock);
            var response = Client.SetFixedAssets(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string UpdateFixedAsset(FixedAssetModel stock)
        {
            var request = new FixedAssetRequest().Prepare();
            request.Action = "Update";
            request.FixedAsset = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(stock);
            var response = Client.SetFixedAssets(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string DeleteFixedAsset(int stockId)
        {
            var request = new FixedAssetRequest().Prepare();
            request.Action = "Delete";
            request.Criteria = new FixedAssetCriteria() { FixedAssetId = stockId };

            var response = Client.SetFixedAssets(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }
        #endregion

        #region FixedAssetCategory
        public int GetPageSizeFixedAssetCategorys()
        {
            var request = new FixedAssetCategoryRequest().Prepare();
            request.LoadOptions = new[] { "TotalPage" };

            var response = Client.GetFixedAssetCategorys(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.TotalPage;
        }

        public IList<FixedAssetCategoryModel> GetAllFixedAssetCategorys()
        {
            var request = new FixedAssetCategoryRequest().Prepare();
            request.LoadOptions = new[] { "FixedAssetCategorys" };
            request.Options = OptionType.IsUnit | OptionType.NonPaging;

            var response = Client.GetFixedAssetCategorys(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.FixedAssetCategorys).ToList();
        }

        public IList<FixedAssetCategoryModel> GetFixedAssetCategorys(int currentPage)
        {
            var request = new FixedAssetCategoryRequest().Prepare();

            request.LoadOptions = new[] { "FixedAssetCategorys" };
            request.Options = OptionType.IsUnit | OptionType.IsPaging;
            request.CurrentPage = currentPage;

            var response = Client.GetFixedAssetCategorys(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.FixedAssetCategorys);
        }

        public IList<FixedAssetCategoryModel> GetFixedAssetCategorysForComboTree(int fixedAssetCategoryId)
        {
            var request = new FixedAssetCategoryRequest().Prepare();
            request.LoadOptions = new[] { "FixedAssetCategorys", "ForComboTree" };
            request.Options = OptionType.IsUnit;
            request.Criteria = new FixedAssetCategoryCriteria() { FixedAssetCategoryId = fixedAssetCategoryId };

            var response = Client.GetFixedAssetCategorys(request);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);

            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.FixedAssetCategorys);
        }

        public FixedAssetCategoryModel GetFixedAssetCategory(int stockId)
        {
            var request = new FixedAssetCategoryRequest().Prepare();
            request.LoadOptions = new[] { "FixedAssetCategory" };
            request.Criteria = new FixedAssetCategoryCriteria() { FixedAssetCategoryId = stockId };
            var response = Client.GetFixedAssetCategorys(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObject(response.FixedAssetCategory);
        }

        public string AddFixedAssetCategory(FixedAssetCategoryModel stock)
        {
            var request = new FixedAssetCategoryRequest().Prepare();
            request.Action = "Create";
            request.FixedAssetCategory = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(stock);
            var response = Client.SetFixedAssetCategorys(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string UpdateFixedAssetCategory(FixedAssetCategoryModel stock)
        {
            var request = new FixedAssetCategoryRequest().Prepare();
            request.Action = "Update";
            request.FixedAssetCategory = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(stock);
            var response = Client.SetFixedAssetCategorys(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string DeleteFixedAssetCategory(int stockId)
        {
            var request = new FixedAssetCategoryRequest().Prepare();
            request.Action = "Delete";
            request.Criteria = new FixedAssetCategoryCriteria() { FixedAssetCategoryId = stockId };

            var response = Client.SetFixedAssetCategorys(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }
        #endregion

        #region Unit

        public IList<UnitModel> GetAllUnits()
        {
            var request = new UnitRequest().Prepare();
            request.LoadOptions = new[] { "Units" };
           // request.Options = OptionType.IsUnit | OptionType.NonPaging;

            var response = Client.GetUnits(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Units).ToList();
        }

        public int GetPageSizeUnits()
        {
            var request = new UnitRequest().Prepare();
            request.LoadOptions = new[] { "TotalPage" };

            var response = Client.GetUnits( request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.TotalPage;
        }

        public IList<UnitModel> GetUnits(int currentPage)
        {
            var request = new UnitRequest().Prepare();

            request.LoadOptions = new[] { "Units" };
            request.Options = OptionType.IsUnit | OptionType.IsPaging;
            request.CurrentPage = currentPage;

            var response = Client.GetUnits(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Units);
        }

        public UnitModel GetUnit(int unitId)
        {
            var request = new UnitRequest().Prepare();
            request.LoadOptions = new[] { "Unit" };
            request.Criteria = new UnitCriteria() { UnitId = unitId };
            var response = Client.GetUnits(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObject(response.Unit);
        }

        public string AddUnit(UnitModel unit)
        {

            var request = new UnitRequest().Prepare();
            request.Action = "Create";
            request.Unit = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(unit);
            var response = Client.SetUnits(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string UpdateUnit(UnitModel unit)
        {
            var request = new UnitRequest().Prepare();
            request.Action = "Update";
            request.Unit = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(unit);
            var response = Client.SetUnits(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string DeleteUnit(int unitId)
        {
            var request = new UnitRequest().Prepare();
            request.Action = "Delete";
            request.Criteria = new UnitCriteria() { UnitId = unitId };

            var response = Client.SetUnits( request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }
        #endregion

        #region Vendor

        public IList<VendorModel> GetAllVendors()
        {
            var request = new VendorRequest().Prepare();
            request.LoadOptions = new[] { "Vendors" };
            request.Options = OptionType.IsUnit | OptionType.NonPaging;

            var response = Client.GetVendors(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Vendors).ToList();
        }

        public int GetPageSizeVendors()
        {
            var request = new VendorRequest().Prepare();
            request.LoadOptions = new[] { "TotalPage" };

            var response = Client.GetVendors(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.TotalPage;
        }

        public List<VendorModel> GetVendorsByActive(bool isActive)
        {
            var request = new VendorRequest().Prepare();

            request.LoadOptions = new[] { "Vendors" };
         //   request.Options = OptionType.IsUnit | OptionType.IsPaging;
           // request.CurrentPage = currentPage;

            var response = Client.GetVendors(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Vendors).ToList();
        }

        public IList<VendorModel> GetVendors(int currentPage)
        {
            var request = new VendorRequest().Prepare();

            request.LoadOptions = new[] { "Vendors" };
            request.Options = OptionType.IsUnit | OptionType.IsPaging;
            request.CurrentPage = currentPage;

            var response = Client.GetVendors(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.Vendors);
        }

        public VendorModel GetVendor(int vendorId)
        {
            var request = new VendorRequest().Prepare();
            request.LoadOptions = new[] { "Vendor" };
            request.Criteria = new VendorCriteria() { VendorId = vendorId };
            var response = Client.GetVendors(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObject(response.Vendor);
        }

        public string AddVendor(VendorModel vendor)
        {
            var request = new VendorRequest().Prepare();
            request.Action = "Create";
            request.Vendor = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(vendor);
            var response = Client.SetVendors(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string UpdateVendor(VendorModel vendor)
        {
            var request = new VendorRequest().Prepare();
            request.Action = "Update";
            request.Vendor = WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.ToDataTransferObject(vendor);
            var response = Client.SetVendors(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        public string DeleteVendor(int vendorId)
        {
            var request = new VendorRequest().Prepare();
            request.Action = "Delete";
            request.Criteria = new VendorCriteria() { VendorId = vendorId };

            var response = Client.SetVendors(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return response.Message;
        }

        #endregion

        #region ReportList

        /// <summary>
        /// Gets the report lists.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.ApplicationException"></exception>
        public List<ReportListModel> GetReportLists()
        {
            //var request = PrepareRequest(new ReportListRequest());
            //request.LoadOptions = new[] { "ReportLists" };

            var request = new ReportListRequest().Prepare();
            request.LoadOptions = new[] { "ReportLists" };

            //var response = ReportListClient.GetReportLists(request);
            var response = Client.GetReportLists(request);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            
            Correlate(request, response);
            return DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.ReportLists);
        }

        /// <summary>
        /// Gets the report lists by report group.
        /// </summary>
        /// <param name="reportGroupId">The report group identifier.</param>
        /// <returns>
        /// List{ReportListModel}.
        /// </returns>
        /// <exception cref="System.ApplicationException"></exception>
        public List<ReportListModel> GetReportListsByReportGroup(int reportGroupId)
        {
            var request = new ReportListRequest().Prepare();
            request.LoadOptions = new[] { "ReportListsByReportGroup" };
            request.ReportGroupId = reportGroupId;
            var response = Client.GetReportLists(request);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            Correlate(request, response);
            return DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.ReportLists);
        }

        /// <summary>
        /// Gets the report list by identifier.
        /// </summary>
        /// <param name="reportListId">The report list identifier.</param>
        /// <returns>
        /// ReportListModel.
        /// </returns>
        /// <exception cref="System.ApplicationException"></exception>
        public ReportListModel GetReportListById(string reportListId)
        {
            //var request = PrepareRequest(new ReportListRequest());
            //request.LoadOptions = new[] { "ReportList" };
            var request = new ReportListRequest().Prepare();
            request.LoadOptions = new[] { "ReportLists" };
            request.ReportListId = reportListId;
            var response = Client.GetReportLists(request);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);

            return DataTransferObjectMapper.Mapper.FromDataTransferObject(response.ReportList);
        }

        /// <summary>
        /// Gets the report groups.
        /// </summary>
        /// <returns>
        /// List{ReportGroupModel}.
        /// </returns>
        /// <exception cref="System.ApplicationException"></exception>
        public List<ReportGroupModel> GetReportGroups()
        {
            var request = new ReportGroupRequest().Prepare();
            request.LoadOptions = new[] { "ReportGroups" };
            var response = Client.GetReportGroups(request);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);

            return DataTransferObjectMapper.Mapper.FromDataTransferObject(response.ReportGroups);
        }

        /// <summary>
        /// Gets the report group by identifier.
        /// </summary>
        /// <param name="reportGroupId">The report group identifier.</param>
        /// <returns>
        /// ReportGroupModel.
        /// </returns>
        /// <exception cref="System.ApplicationException"></exception>
        public ReportGroupModel GetReportGroupById(int reportGroupId)
        {
            
            var request = new ReportGroupRequest().Prepare();
            request.LoadOptions = new[] { "ReportGroup" };
            request.ReportGroupId = reportGroupId;

            var response = Client.GetReportGroups(request);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);

            return DataTransferObjectMapper.Mapper.FromDataTransferObject(response.ReportGroup);
        }

        #endregion

        #region RefType
        public IList<RefTypeModel> GetRefTypes()
        {
            var request = new RefTypeRequest().Prepare(); 
            request.LoadOptions = new[] { "RefTypes" };

            var response = Client.GetRefTypes(request);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);

            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.RefTypes);
      
        }

        #endregion

        #region VoucherType

        public IList<VoucherTypeModel> GetVoucherTypes()
        {
            var request = new VoucherTypeRequest().Prepare(); 
            request.LoadOptions = new[] { "VoucherTypes" };

            var response = Client.GetVoucherTypes(request);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.VoucherTypes);
        }

        public IList<VoucherTypeModel> GetVoucherTypesActive()
        {
            var request = new VoucherTypeRequest().Prepare(); 
            request.LoadOptions = new[] { "VoucherTypes", "IsActive" };

            var response = Client.GetVoucherTypes(request);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.VoucherTypes);

        }
        #endregion

        #region Reports
        public IList<StockBacklogModel> GetStockBacklog(DateTime fromDate, DateTime toDate, string stockIdList)
        {
            var request = new ReportRequest();
            request.FromDate = fromDate;

            request.LoadOptions = new[] { "Reports", "StockBacklog" };
           
            request.ToDate = toDate;
            //request.CurrencyCode = currencyCode;
            //request.AmounType = amounType;
            //request.AccountNumber = accountnumber;
            request.ListStockId = stockIdList;
            var response = Client.GetReports(request);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);

            //return Mapper.FromDataTransferObjects(response.StockBacklog);
            return DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.StockBacklog);
        }
        #endregion   





        public List<InventoryItemModel> GetInventoryItemListByStock(int itemStock, int refId, DateTime postDate)
        {
            var request = new InventoryItemRequest().Prepare(); 
            request.LoadOptions = new[] { "ItemStock" };
            request.ItemStockId = itemStock;
            request.InventoryItemId = refId;
            request.PostDate = postDate;
            //request.CurrencyCode = currencyCode;
            var response = Client.GetInventoryItems(request);
            Correlate(request, response);
            if (response.Acknowledge != AcknowledgeType.Success) throw new ApplicationException(response.Message);
            return WindowsForms.AOnline.Model.DataTransferObjectMapper.Mapper.FromDataTransferObjects(response.InventoryItems).ToList();
        }



        #region OpeningAccountEntry

        public IList<BusinessObjects.Opening.OpeningAccountEntryModel> GetOpeningAccountEntries()
        {
            throw new NotImplementedException();
        }

        public BusinessObjects.Opening.OpeningAccountEntryModel GetOpeningAccountEntry(string accountCode)
        {
            throw new NotImplementedException();
        }

        public long UpdateOpeningAccountEntry(BusinessObjects.Opening.OpeningAccountEntryModel openingAccountEntry)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}